#include "comboxdelegate.h"


ComBoxDelegate::ComBoxDelegate( QObject * parent )
    : QItemDelegate(parent)
{
}

QWidget * ComBoxDelegate::createEditor( QWidget * parent,
                                     const QStyleOptionViewItem &,
                                     const QModelIndex & ) const
{
QIcon green = QIcon( QPixmap(":/binary/green_b.png") );
QIcon yellow = QIcon( QPixmap(":/binary/yellow_b.png") );
QIcon red = QIcon(QPixmap(":/binary/red_b.png") );
QIcon blue = QIcon(QPixmap(":/binary/blue_b.png") );

QComboBox * editor = new QComboBox(parent);
editor->setMaxVisibleItems(15);

editor->addItem( red, tr("Skip Column") );
editor->addItem( blue, tr("Description") );

Schema * schema = new Schema;
    if ( NULL == schema )
    {
    return editor;
    }
QMap<int, QString> headers = schema->headers();
QList<int> strings = schema->strings();

    for ( int i = 1; i < headers.size(); ++i )
    {
        if ( true == strings.contains(i) )
        {
        editor->addItem( green, headers.value(i) );
        }
        else
        {
        editor->addItem( yellow, headers.value(i) );
        }
    }

editor->installEventFilter( const_cast<ComBoxDelegate *>(this) );
return editor;
}

void ComBoxDelegate::setModelData( QWidget * editor,
                                   QAbstractItemModel * model,
                                   const QModelIndex & index ) const
{
QComboBox * comboBox = static_cast<QComboBox *>(editor);
QString value = comboBox->currentText();
model->setData( index, value );
}



